// 格式化ISO时间字符串为更易读的格式
const formatISOTime = isoTime => {
  if (!isoTime) return ''
  try {
    let date;
    // 处理不同的时间格式
    if (typeof isoTime === 'string') {
      // 如果是纯字符串格式如 "2025-10-30T20:37:18"
      if (isoTime.includes('T') && !isoTime.includes('+') && !isoTime.includes('Z')) {
        // 添加默认时区偏移（假设为东八区）
        date = new Date(isoTime + '+08:00');
      } else {
        date = new Date(isoTime);
      }
    } else {
      date = new Date(isoTime);
    }
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()
    return `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')} ${hour.toString().padStart(2, '0')}:${minute.toString().padStart(2, '0')}:${second.toString().padStart(2, '0')}`
  } catch (e) {
    console.error('时间格式化错误:', e)
    return isoTime
  }
}

module.exports = {
  formatISOTime
}